package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.ServiceEvaluationMapper;
import com.tzbank.back.service.ServiceEvaluationService;
import com.tzbank.entity.backstage.ProductEvaluation;
import com.tzbank.entity.backstage.ServiceEvaluation;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import net.sf.json.JSONObject;
/**
 * 服务评价配置
 * @author 蔡宇钿
 *2018年5月29日
 *更新 蔡宇钿 2018.6.1
 */
@Service
public class ServiceEvaluationServiceImpl implements ServiceEvaluationService {
	
	@Autowired
	private ServiceEvaluationMapper serviceEvaluationMapper;
	
	@Transactional
	@Override
	public Map<String, Object> deleteByserviceautoId(ProductEvaluation cptcInfoJson) throws Exception{
		// 通过逻辑方式实现删除
		cptcInfoJson.setStatus("0");
		cptcInfoJson.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.serviceEvaluationMapper.deleteByserviceautoId(cptcInfoJson);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> getlistByevaluation(String evaluation) throws Exception{
		// 按照evaluation查询
		ServiceEvaluation serviceEvaluation = this.serviceEvaluationMapper.getlistByevaluation(evaluation);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), serviceEvaluation);
	}

	@Override
	public Map<String, Object> getlistService() throws Exception{
		// 查询全部
		List<ServiceEvaluation> serviceEvaluation = this.serviceEvaluationMapper.getlistService();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), serviceEvaluation);
	}

	@Transactional
	@Override
	public Map<String, Object> addService(ServiceEvaluation cptcInfoJson) throws Exception{
		// 增加配置
//		ServiceEvaluation serviceEvaluation = (ServiceEvaluation) JSONObject.toBean(cptcInfoJson, ServiceEvaluation.class);
		cptcInfoJson.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		cptcInfoJson.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.serviceEvaluationMapper.addService(cptcInfoJson);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> modifyByserviceautoId(ServiceEvaluation cptcInfoJson) throws Exception{
		// 更新配置
		cptcInfoJson.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.serviceEvaluationMapper.modifyByserviceautoId(cptcInfoJson);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
